﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Lister;
using COFE.Core;
using COFE.Core.Validater;
using System.IO;
using COFE.Core.Utils;
using COFE.Core.Entry;

namespace COFE.Data.UnitTest
{


    public class DummyDBPropertyProvider : ISecondaryPropertyProvider<IFileSystemInfo>
    {
        public enum DummyProperties : int
        {
            [PropertyType(0, typeof(Int32))]
            DummyInt = 1001,
            [PropertyType("", typeof(string))]
            DummyString,
            [PropertyType(typeof(Single))]
            DummySingle,
            [PropertyType(typeof(Guid))]
            DummyGuid,
            [PropertyType(typeof(Stream))]
            DummyStream,
            [PropertyType("failed", typeof(string))]
            [PrimaryProperty]
            DummyPrimaryProperty
        }

        public static void EnableDummySecondaryPropertyProvider()
        {
            COFEShared.SecondaryPropertyProviderManager.Register(new DummyDBPropertyProvider());
            COFEShared.PropertyDictionary.RegisterProperties<DummyProperties>();
        }


        public object[] GetSupportedProperty(IFileSystemInfo sourceObj)
        {
            if (sourceObj is IFileSystemInfo)
                return new object[] { DummyProperties.DummyInt, DummyProperties.DummyString, 
                    DummyProperties.DummyStream, DummyProperties.DummySingle, DummyProperties.DummyGuid,
                DummyProperties.DummyPrimaryProperty };
            return new object[] { };
        }

        public bool IsPropertyReadOnly(IFileSystemInfo sourceObj, object property)
        {
            return true;
        }

        public PropertyPair GetProperty(IFileSystemInfo sourceObj, object property)
        {
            if (sourceObj is IFileSystemInfo)
            {
                switch ((int)property)
                {
                    case (int)DummyProperties.DummyInt:
                        return new PropertyPair(property, (sourceObj as IFileSystemInfo).ParseName.Length);
                    case (int)DummyProperties.DummyString:
                        return new PropertyPair(property, (sourceObj as IFileSystemInfo).ParseName + "_DUMMY");
                    case (int)DummyProperties.DummySingle:
                        return new PropertyPair(property, (Single)(sourceObj as IFileSystemInfo).ParseName.Length);
                    case (int)DummyProperties.DummyGuid:
                        return new PropertyPair(property, Guid.Empty);
        
                    case (int)DummyProperties.DummyStream:
                        var ms = new MemoryStream();
                        var sw = new StreamWriter(ms);
                        sw.WriteLine((sourceObj as IFileSystemInfo).ParseName);
                        sw.Flush();
                        ms.Seek(0, SeekOrigin.Begin);
                        return new PropertyPair(property, ms);
                    
                    case (int)DummyProperties.DummyPrimaryProperty:
                        return new PropertyPair(property, "success");
                }
            }
            throw new NotSupportedException();
        }

        public void SetProperty(IFileSystemInfo sourceObj, object property, object value)
        {
            throw new NotImplementedException();
        }

        public DummyDBPropertyProvider()
        {
        }

        #region Methods


        #endregion

        #region Data



        #endregion

        #region Public Properties

        #endregion
    }
}
